<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page language="java" import="net.sf.json.JSONObject" %> 
<%
try {
String connectionURL = "jdbc:mysql://webproject2.cse.ust.hk/BookwarmMobile?user=BookwarmMobile&password=bookwarm"; 

Connection connection = null;

Class.forName("com.mysql.jdbc.Driver").newInstance(); 

connection = DriverManager.getConnection(connectionURL);

if(!connection.isClosed()){
String newAccountName = null; 

newAccountName = request.getParameter("username");

JSONObject newAccountInfo = new JSONObject();

Statement statement0 = null;
ResultSet rs0 = null;
statement0 = connection.createStatement();
String query0 = "SELECT * FROM Users WHERE AccountName = '" + newAccountName + "';";
rs0 = statement0.executeQuery(query0);
if(rs0.next()) {
String newPhoneNumber = null;
String newNickName = null;
String newFirstName = null;
String newLastName = null;
String newDateCreated = null;
String newCredit = null;

newPhoneNumber = rs0.getString("Users.PhoneNumber");
newNickName = rs0.getString("Users.NickName");
if(newNickName == null) {
newNickName = "N/A";

}
newFirstName = rs0.getString("Users.FirstName");
if(newFirstName == null) {
newFirstName = "N/A";

}
newLastName = rs0.getString("Users.LastName");
if(newLastName == null) {
newLastName = "N/A";

}
newDateCreated = rs0.getString("Users.DateCreated");
newCredit = rs0.getString("Users.Credit");

newAccountInfo.put("PhoneNumber", newPhoneNumber);
newAccountInfo.put("NickName", newNickName);
newAccountInfo.put("FirstName", newFirstName);
newAccountInfo.put("LastName", newLastName);
newAccountInfo.put("DateCreated", newDateCreated);
newAccountInfo.put("Credit", newCredit);

}
statement0.close();

out.print(newAccountInfo);

}

connection.close();

}
catch(Exception ex){
out.print(ex);

}  
%>